import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_echarts/flutter_echarts.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/resources/str_res_keys.dart';

import '../../devices/device_tab/device_detail/new_air_cooling_page/temperature_full_chart/component/full_screen_back.dart';

/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2024年03月27日 14:41
 */
class FullScreenPowerChart extends StatelessWidget {
  List<dynamic>? data;
  List<String> paramList;
  final List<dynamic>? timeList;
  // final num maxValue;
  // final num minValue;
  String? tooltipFormatter;
  FullScreenPowerChart(
      {super.key,
        required this.data,
        required this.paramList,
        required this.timeList,
        // required this.maxValue,
        // required this.minValue,
        this.tooltipFormatter});

  @override
  Widget build(BuildContext context) {
    Log.d('=tooltipFormattertooltipFormatter===' + data.toString());
    return  Scaffold(

        backgroundColor: Colors.white,
        body: SafeArea(
            child: RotatedBox(
              quarterTurns: 1,
              child: Scaffold(
                backgroundColor: Colors.white,
                body: Column(
                  children: [
                    // Gaps.vGap10,
                    FullScreenBack(() {
                      Log.d('back');
                      navigator?.pop();
                    }),
                    Expanded(
                        child: Container(
                          color: Colors.white,
                          padding: EdgeInsets.only(left: 0, right: 0),
                          child: Echarts(
                            captureAllGestures: false,
                            option: '''
  {
  color: ['#3DD598', '#007DFF'],
 /// 纵轴
  yAxis: [
  
    {
      type: 'value',
      name: 'kWh',
       max:function (value) {
             return (typeof value.max === 'number' && isNaN(value.max))?1:null;
        },
       min:function (value) {
             return (typeof value.min === 'number' && isNaN(value.min))?0:null;
        },
       alignTicks: true,
      nameTextStyle: {
        align: "center"
      },
      align: 'left',
      padding: [3, 4, 5, 6],
      verticalAlign: 'top',
      nameLocation: 'end',
      position: 'left',
      splitLine: {
        lineStyle: {
          type: 'dashed', //虚线
        },
      },
    },
    // {
    //   type: 'value',
    //   name: ${jsonEncode('${ResKey.income.tr}(${ResKey.yuan.tr})')},
    //    nameTextStyle: {
    //     align: "center"
    //   },
    //   nameLocation: 'end',
    //   splitLine: {
    //     lineStyle: {
    //       type: 'dashed', //虚线
    //     },
    //   },
    // },
  ],
     /// 横轴
  xAxis: {
    type: 'category',  
    data: ${jsonEncode(timeList)},                
    axisLine:{
      show: false,
    }, 
    
    axisTick: {
      show: false
    }, 
    axisLabel: {
      color: '#999999',
      fontSize: 11,
      // interval: function (index) { // 自定义间隔函数 
      //     if (index % 4 === 0) { // 每四小时显示一次  // 返回值是五分钟为一个间隔
      //         return true;
      //     } else {
      //         return false;
      //     }
      // },
    },
  },
  dataZoom: [
    {
      type: 'inside',
      realtime: false,
    },
    {
      start: 0,
       bottom: 50,
      end: 0,
      height: 10,
      realtime: false,
    },
  ],
  /// 坐标轴
  grid: {
    top: 30,
    bottom: 75,
    containLabel: true,
    right: 20,
    left:10,
  },
  legend: {
    show: true,
    icon: 'rect',
    itemHeight: 3,
    itemWidth: 12,
        bottom: 5,
    // right: 20,
    // left:30,
  },
  
  ///提示框
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(0,0,0,0.85)',
    borderWidth: 0,
    opacity: 0.2,
    confine: true,
    padding: [
      10, // 上
      8, // 右
      10, // 下
      8 // 左
    ],
    textStyle: {
      color: 'white'
    },
    axisPointer: {
      /// 坐标轴指示器配置项
      lineStyle: {
        color: 'rgba(0,0,0,0.09)',
        position: function (pt) {
          return [pt[0], 500];
        }
      }
    },

    formatter: $tooltipFormatter

  },
    /// 图表数据
   series: ${jsonEncode(data)},
}
  ''',
                          ),
                        ))
                  ],
                ),
              ),
            )));
  }
}
